package com.wise.service.cms.content.category;

import cn.hutool.core.bean.BeanUtil;
import com.wise.entities.content.ProductCategory;
import com.wise.framework.basic.DateTimeUtil;
import com.wise.framework.daomodel.DaoSave;
import com.wise.framework.session.CurrentUserId;
import com.wise.framework.session.GetAcceptLanguage;
import com.wise.summer.v1.cms.content.category.AddCategory;
import org.springframework.stereotype.Service;
import org.summerframework.model.SummerService;
import org.summerframework.model.SummerServiceBean;

/**
 * @author shaoming
 * @date 2019-09-10
 */
@Service
@SummerService
public class AddCategoryService implements SummerServiceBean<AddCategory> {

	@Override
	public void sum(AddCategory summer) {
		if (summer.getCategoryType() == null) {
			summer.setCategoryType(0);
		}
		String lang = GetAcceptLanguage.s(true);
		ProductCategory productCategory = new ProductCategory();
		BeanUtil.copyProperties(summer, productCategory);
		productCategory.setLang(lang);
		productCategory.setCreatedBy(CurrentUserId.s(true));
		productCategory.setCreationDate(DateTimeUtil.timestampNow());
		DaoSave.s(productCategory);

		summer.setSummerResult(productCategory);
	}
}
